package com.example.thread;


import java.util.Queue;
import java.util.UUID;
import java.util.concurrent.ConcurrentLinkedQueue;
import java.util.concurrent.CountDownLatch;

public class Test1 {


    private static CountDownLatch countDownLatch;

    private final static Queue<String> logQueue = new ConcurrentLinkedQueue<>();

    public static void main(String[] args) throws InterruptedException {


        // 设置处理线程
        new Thread(() -> {
            if (logQueue.size() > 0) {
                System.out.println("xxxxxxxxxxxxx");
            } else {
                countDownLatch = new CountDownLatch(1);
                try {
                    countDownLatch.await();
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }
        }, "xxx--->111111111").start();

        Thread.sleep(3000);

        // 设置处理线程
        new Thread(() -> {
            try {
                logQueue.offer(UUID.randomUUID().toString());
                if (countDownLatch != null) {
                    countDownLatch.countDown();
                }

                if (countDownLatch != null) {
                    countDownLatch.countDown();
                }
            } catch (Exception e) {
                e.printStackTrace();
            }
        }, "xxx--->2222222222222222").start();

    }
}
